package com.hyy.service.serviceImpl;


import com.hyy.bean.MaskUser;
import com.hyy.dao.UserDao;
import com.hyy.dao.daoImpl.UserDaoImpl;
import com.hyy.service.UserService;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {

	UserDao userDao = new UserDaoImpl();

	@Override
	public MaskUser login(String username, String password) {
		MaskUser user = null;
		try {
			user = userDao.selectLogin(username,password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}

	@Override
	public boolean register(MaskUser user) {
		try {
			if (userDao.checkUsername(user.getUsername())){
				return (userDao.insert(user)==1);
			}
			return false;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean updatePassword(Long userId, String newPassword){
		try {
			return userDao.updatePasswordByUserId(userId,newPassword);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;

	}

	@Override
	public boolean updateUser(MaskUser user) {
		try {
			return userDao.updateByPrimaryKey(user);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public MaskUser adminLogin(String phone, String password) {
		return null;
	}
}
